<template>
	<view class="content">
		<image class="logo" :src="logo"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
		<view class="btn-denglu d-flex align-items justify-content-center" @click="denglu">
			<image src="../../static/login/weichat.png" mode="widthFix"></image>
			<view class="">微信一键登录</view>
		</view>
		<!-- <view class="mima">密码登录</view> -->
		<view class="uni-list-cell">
			<view>
				<u-checkbox-group @change="checkboxChange">
					<u-checkbox shape="circle" :customStyle="{marginBottom: '8px'}" :checked="choosechecked"
						activeColor="#55aaff">
					</u-checkbox>
				</u-checkbox-group>
			</view>
			<view class="yuedu">
				<text>我已阅读并同意</text>
				<text class="xieyi" @click="xieyi(1)">用户协议</text>
			</view>
		</view>
		<!-- 底部登录 -->
		<view class="foot_btn_yuedu">
			<view class="">登录代表同意 <text class="fuwu"  @click="xieyi(2)">《服务协议》</text>及 <text class="fuwu"  @click="xieyi(3)">《隐私协议》</text> </view>
			<view class="">登录前请阅读</view>
		</view>
		<!-- 小程序隐私协议 -->
		<privacy-popup></privacy-popup>
	</view>
</template>

<script>
	import PrivacyPopup from "@/components/privacy-popup/privacy-popup.vue"
	import {
		login_mini,
		index
	} from '@/api/user.js'
	export default {
		data() {
			return {
				title: '****工程施工',
				code: '',
				choosechecked: false,
				logo:'',
			}
		},
		components: {
			PrivacyPopup
		},
		onLoad() {
			this.top_img()
		},
		methods: {
			
			checkboxChange(n) {
				console.log('change', n);
				this.choosechecked = n.length > 0 ? true : false
			},
			xieyi(id) {
				uni.navigateTo({
					url: '/pages/login/xieyi?id=' + id
				})
			},
			// 替换logo
			top_img(){
				index({}).then(res => {
					console.log("替换logog",res);
					if(res.code == 1){
						this.logo = res.data.xieyi.logo
						this.title = res.data.xieyi.sitename
						console.log("打飞机上课啦防静电上课啦飞机啊双打卡拉法基大山卡拉",this.top_img);
					}
				})
			},
			denglu() {
				let that = this
				if (!that.choosechecked) return uni.showToast({
					title: '请先勾选阅读协议',
					icon: 'none',
				})
				uni.login({
					provider: "weixin",
					success(a) {
						console.log('getUserProfile success weixin success', a);
						uni.setStorageSync("code", a.code)
						var data = {
							code: a.code,
							// reg_code: that.code,
						}
						login_mini(data).then(res => {
							console.log("登录成功", res);
							if (res.code == 1) {
								let tmp = {}
								tmp.userinfo = res.data.userInfo
								uni.setStorageSync('token', res.data.userInfo.token)
								uni.setStorageSync('user_id', res.data.userInfo.user_id)
								uni.setStorageSync('userInfo', res.data.userInfo)
								if (res.data.userInfo.nickname && res.data.userInfo.avatar && res.data
									.userInfo.mobile) {
									if (typeof that.$util.prePage().get_userdetail == 'function') {
										that.$util.prePage().get_userdetail()
									}
									if (typeof that.$util.prePage().get_juese_list == 'function') {
										that.$util.prePage().get_juese_list()
									}
									if (typeof that.$util.prePage().get_role == 'function') {
										that.$util.prePage().get_role()
									}
									
									uni.navigateBack({
										delta: 1
									})

								} else {
									uni.navigateTo({
										url: '/pages/login/getLoginInfo?avatar=' + res.data
											.userInfo.avatar_url + '&nickname=' + res.data.userInfo
											.nickname
									})
								}

							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								})
							}
						})
					}
				})
			}
		}
	}
</script>

<style>
	.fuwu {
		color: #1A66FF !important;
	}

	.foot_btn_yuedu {
		font-size: 24rpx;
		font-weight: 250;
		line-height: 40rpx;
		text-align: center;
		margin-top: 50%;
		/* 登录代表同意 */
		color: #646466
	}

	.xieyi {
		color: #333333 !important;
	}

	.yuedu {
		font-size: 28rpx;
		margin-top: -20rpx;
		color: #A1A1A1;
	}

	.uni-list-cell {
		display: flex;
		width: 650rpx;
		font-size: 22rpx;
		color: #333;
		margin: auto;
		margin-top: 140rpx;
		align-items: center;
		justify-content: center;
	}

	.mima {
		font-size: 28rpx;
		text-align: center;
		color: #303030;
		margin-top: 40rpx;
	}

	.btn-denglu view {
		font-size: 32rpx;
		color: #fff;
		margin-left: 20rpx;
	}

	.btn-denglu image {
		width: 56rpx;
		display: block;
	}

	.btn-denglu {
		width: 622rpx;
		height: 96rpx;
		border-radius: 8rpx;
		opacity: 1;
		background: #51B13E;
		margin-top: 112rpx;
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 144rpx;
		width: 144rpx;
		margin-top: 96rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 40rpx;
		box-shadow: 0px 8px 16px 0px rgba(48, 48, 48, 0.1);
	}

	.title {
		font-size: 28rpx;
		color: #303030;
	}
</style>